From f621da5bdf42549731820201dd4bd570fb37bdb2 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Thu, 27 Mar 2008 17:14:41 +0000 Subject: [PATCH] ioemu: Two qcow2 bug fixes from upstream qemu. [Qemu-devel] PATCH: qcow2 image corruption http://lists.gnu.org/archive/html/qemu-devel/2007-03/msg00773.html [Qemu-devel] [PATCH] qcow2: release refcount table clusters of the old table, after growing the refcount table http://lists.gnu.org/archive/html/qemu-devel/2007-04/msg00043.html Signed-off-by: Kevin Wolf --- tools/ioemu/block-qcow2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/ioemu/block-qcow2.c b/tools/ioemu/block-qcow2.c index a5f8255389..64ec49034a 100644 --- a/tools/ioemu/block-qcow2.c +++ b/tools/ioemu/block-qcow2.c @@ -1886,6 +1886,8 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size) int64_t table_offset; uint64_t data64; uint32_t data32; + int old_table_size; + int64_t old_table_offset; if (min_size <= s->refcount_table_size) return 0; @@ -1931,10 +1933,14 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size) &data32, sizeof(data32)) != sizeof(data32)) goto fail; qemu_free(s->refcount_table); + old_table_offset = s->refcount_table_offset; + old_table_size = s->refcount_table_size; s->refcount_table = new_table; s->refcount_table_size = new_table_size; + s->refcount_table_offset = table_offset; update_refcount(bs, table_offset, new_table_size2, 1); + free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t)); return 0; fail: free_clusters(bs, table_offset, new_table_size2); -- 2.30.2